package com.http;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

import com.android.ocean.util.common.StringUtil;
import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;

/**
 * 
 * @ClassName:ForgetPwdMsgTask
 * @Description:TODO
 * @author zhuw
 * @date 2013-11-6 下午7:48:19
 */
public class ForgetPwdMsgTask extends AsyncTask<String, Void, ResultString> {

	NetCallBack callback;

	public ForgetPwdMsgTask(NetCallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultString doInBackground(String... params) {
		ResultString data = null;
		try {
			ArrayList<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
			paramPairs.add(new BasicNameValuePair("mobile", params[0]));
			ResEntity re = NetConUtil.postByForm(ServerPath.FORGET_PWD_PATH,
					paramPairs);
			System.out.println(re.jsonStr);
			if (re.code == ResEntity.S_OK) {

				data = new ResultString(CommonData.H_FLAG_SUCCESS, null,
						StringUtil.unicodeToString(re.jsonStr));
			} else if (re.code == ResEntity.S_FAILED) {

				data = new ResultString(CommonData.H_FLAG_ERROR, "code:"
						+ re.code + "    " + StringUtil.unicodeToString(re.jsonStr), null);

			} else {
				data = new ResultString(CommonData.H_FLAG_ERROR, "code:"
						+ StringUtil.unicodeToString(re.jsonStr) + ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data = new ResultString(CommonData.H_FLAG_ERROR,
					ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultString result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.onSuccess(result.result);

		} else {
			callback.onError(result.msg);
		}

	}
}
